{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9b206acf-66c3-411a-8139-f34a29dcacb9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据合并完成，已保存到combined_data.csv\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import os\n",
    "\n",
    "# 文件目录\n",
    "directory = './class_split/'\n",
    "\n",
    "# 文件列表\n",
    "files = [\n",
    "    'BENIGN.csv', 'DrDoS_DNS.csv', 'DrDoS_LDAP.csv', 'DrDoS_MSSQL.csv',\n",
    "    'DrDoS_NTP.csv', 'DrDoS_NetBIOS.csv', 'DrDoS_SNMP.csv', 'DrDoS_UDP.csv',\n",
    "    'LDAP.csv', 'MSSQL.csv', 'NetBIOS.csv', 'Portmap.csv',\n",
    "    'Syn.csv', 'TFTP.csv', 'UDP.csv', 'UDP-lag.csv'\n",
    "]\n",
    "\n",
    "# 创建空的DataFrame\n",
    "combined_data = pd.DataFrame()\n",
    "\n",
    "# 对每个文件进行处理\n",
    "for file in files:\n",
    "    file_path = os.path.join(directory, file)\n",
    "    # 加载数据\n",
    "    data = pd.read_csv(file_path)\n",
    "    # 随机选取500条数据\n",
    "    sample_data = data.sample(n=500, random_state=1)\n",
    "    # 将数据加入到总的DataFrame中\n",
    "    combined_data = pd.concat([combined_data, sample_data], ignore_index=True)\n",
    "\n",
    "# 保存到新的CSV文件\n",
    "combined_data.to_csv('./combined_data.csv', index=False)\n",
    "\n",
    "print(\"数据合并完成，已保存到combined_data.csv\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d82fdf83-9cb3-4a8f-a781-ff46c41460d1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
